<template>
    <div>
        <HomeView></HomeView>
   <el-card style="width: 500px;">
    <el-form label-width="80px" size="small">
    

      <el-form-item label="用户名">
        <el-input v-model="form.username" disabled autocomplete="off" ></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="form.nickname" autocomplete="off" @input="change($event)"></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.phone" autocomplete="off" @input="change($event)"></el-input>
      </el-form-item>
      <!-- <el-form-item label="地址">
        <el-input type="textarea" v-model="form.address" autocomplete="off" @input="change($event)"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="save">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-card>
    </div>

</template>


<script>
import HomeView from './HomeView.vue';
export default{
    components:{
        HomeView
    },
    data() {
        return{
            form:[{
                username:'',
                phone:'',
                nickname:'',
            }
        ]
        }
    },
    methods:{
        change (e) {
      this.$forceUpdate()
    },
        save(){
            this.$axios.post('/role/updateRole',{
                roleKey:JSON.parse(localStorage.getItem('user')).roleKey,
                rname:this.form.username,
                uname:this.form.nickname,
                phone:this.form.phone,
                
            },{
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
            localStorage.removeItem("user")
            this.$router.push('/')
            this.$message.success("重新登录一下吧")

        }
    },
    created() {
        console.log('start')
        this.role = this.$route.params.role
        console.log(this.role)
        let form= JSON.parse(JSON.stringify(this.role))
        console.log(form)
        // this.form=form[0]
        // console.log(this.form.rname)
        this.form.username = form[0].rname,
        this.form.nickname = form[0].uname,
        this.form.phone = form[0].phone
    }
}
</script>